home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Containrs / sa / next < prev    next >
Text File  |  1996-07-13  |  2KB  |  63 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  3. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  4. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  5. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  6. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  7. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  8.  
  9. -- next.sa: Inherited by elements of singly linked lists.
  10. -------------------------------------------------------------------
  11. abstract class $NEXT{T < $NEXT{T}} is
  12.    -- The interface obeyed by classes which include NEXT{T}.
  13.  
  14.    next:T;            -- Pointer to next element in list, if any.
  15.    
  16.    next(e:T);            -- Set next pointer to `e'.
  17.    
  18.    size:INT;            -- The number of elements in the list
  19.       -- starting with self. Self may be void.
  20.  
  21.    insert(e:T);            -- Insert the single element `e' after self.
  22.       -- Neither may be void.
  23.  
  24.    append(l:T);            -- Append the list `l' to the end of the
  25.       -- list self. self may not be void but `l' may be.
  26. end;
  27.  
  28. -------------------------------------------------------------------
  29. class NEXT{T < $NEXT{T}} < $NEXT{T} is
  30.    -- Inherited by classes whose objects need to point to a list of
  31.    -- objects of type T. Classes which inherit this get a `next'
  32.    -- pointer and some features to manipulate it. It doesn't suport
  33.    -- circular lists.
  34.    
  35.    attr next:T;        -- Pointer to next element in list, if any.
  36.    
  37.    size:INT is
  38.       -- The number of elements in the list starting with self.
  39.       -- Self may be void.
  40.       if void(self) then return 0 end;
  41.       r::=1; n::=next;
  42.       loop until!(void(n)); r:=r+1; n:=n.next end;
  43.       return r end;
  44.  
  45.    insert(e:T)
  46.       -- Insert the single element `e' after self. Neither may be void,
  47.       -- `e.next' must be void.
  48.       pre ~void(self) and ~void(e) and void(e.next) is      
  49.       e.next:=next; next:=e end;
  50.  
  51.    append(l:T) 
  52.       -- Append the list `l' to the end of the list self. self may
  53.       -- not be void but `l' may be.
  54.       pre ~void(self) is
  55.       if void(next) then next:=l; return end;
  56.       last::=next; loop until!(void(last.next)); last:=last.next end;
  57.       last.next:=l end;
  58.  
  59. end;
  60.  
  61. -------------------------------------------------------------------
  62.  
  63.